package com.ld.security.common.core.base.column;

import com.ld.security.common.core.util.StringUtil;
import com.ld.security.common.core.util.TemplateUtil;

import java.util.LinkedList;
import java.util.List;


public class ListString extends LinkedList<String> implements SuperColumn {

    public static final String const_separator="/";


    public ListString() {

    }

    public ListString(List<String> list) {
        for (String s : list) {
            if(!StringUtil.isNull(s)){
                this.add(s);
            }

        }
    }
    public ListString(String ... strings) {
        for (String string : strings) {
            this.add(string);
        }
    }

    public ListString(String val) {
        if(val != null){
            for (String s : val.split(const_separator)) {
                if(s.length() > 0){
                    this.add(s);
                }
            }
        }
    }

    public List<String> toList(){
        LinkedList list =  new LinkedList<>();
        for (String s : this) {
            list.add(s);
        }
        return list;
    }


    @Override
    public String getValue() {
        StringBuffer sb =  new StringBuffer();
        for (String s : this) {
            sb.append(const_separator+s);
        }
        return sb.toString();
    }

    @Override
    public String getLast(){

        if(this.size() == 0) {
            throw new RuntimeException("集合长度为空");
        }
        return  this.get(this.size() - 1);
    }

    @Override
    public String getFirst(){
        if(this.size() == 0) {
            throw new RuntimeException("集合长度为空");
        }
        return  this.get(0);
    }


}
